<template>
    <div>
        <el-breadcrumb separator="/">
            <el-breadcrumb-item>小说章节列表</el-breadcrumb-item>
        </el-breadcrumb>
        <el-card>
            <el-form ref="form" :model="searchForm" label-width="80px" :inline="true" size="small" class="admin_from">
                <el-form-item label="" :class="this.$store.state.windowWidth<=this.$store.state.MaxWidth?'maxWidth':''">
                    <el-input v-model="searchForm.anime_title" placeholder="请输入小说名称"></el-input>
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" size="small" @click="search">查询</el-button>
                </el-form-item>
            </el-form>
            <el-table
                    size="small"
                    :data="tableData"
                    border
                    style="width: 100%">
                <el-table-column
                        prop="anime.title"
                        label="小说名称">
                </el-table-column>
                <el-table-column
                        prop="title"
                        label="章节名称">
                </el-table-column>
                <el-table-column label="状态">
                    <template slot-scope="scope">
                        <span v-if="scope.row.review_status==0">审核中</span>
                        <span v-if="scope.row.review_status==1">审核通过</span>
                        <span v-if="scope.row.review_status==2">审核失败</span>
                    </template>
                </el-table-column>
                <el-table-column
                        prop="created_at"
                        label="创建时间">
                </el-table-column>
                <el-table-column
                        fixed="right"
                        label="操作"
                        width="150px">
                    <template slot-scope="scope">
                        <el-button type="success" plain size="small" @click="pass(scope.row.id, scope.row.anid)"
                                   v-if="scope.row.review_status!==1">通过
                        </el-button>
                        <el-button type="danger" plain size="small" @click="refuse(scope.row.id, scope.row.anid)">拒绝</el-button>
                    </template>
                </el-table-column>
            </el-table>
            <div class="el-pagination">
                <el-pagination
                        background
                        @size-change="changeSize"
                        @current-change="changeCurrent"
                        :current-page="params.pagenum"
                        :page-sizes="[10, 20, 30, 40]"
                        :page-size="params.pagesize"
                        :layout="this.$store.state.paginationLayout"
                        :total="params.totals">
                </el-pagination>
            </div>
        </el-card>
    </div>
</template>

<script>
  import {uploadimg} from '../../utils/common'
  import {formatDate} from '../../utils/common'

  export default {

    name: "User",
    data() {
      return {
        params: {
          pagenum: 1,
          pagesize: 10,
          totals: 0
        },
        tableData: [],
        searchForm: {
          anime_title: '',
        },
      }
    },
    created() {
      this.getList()
    },
    methods: {
      getList() {
        let data = {
          page: this.params.pagenum,
          page_size: this.params.pagesize,
          anime_title: this.searchForm.anime_title,
          is_writer: 1
        };
        this.$axios.post("admin/chapter/index", data).then((res) => {
          this.params.totals = parseInt(res.data.count);
          this.tableData = res.data.list;
        });
      },
      // 每页显示多少条
      changeSize(val) {
        this.params.pagesize = val;
        this.getList()
      },
      // 当前显示的页数
      changeCurrent(val) {
        this.params.pagenum = val;
        this.getList()
      },
      pass(id, anid) {
        let status = 1;
        this.communal(id, status, anid)
      },
      refuse(id, anid) {
        let status = 2;
        this.communal(id, status, anid)
      },
      communal(id, status, anid) {
        this.$confirm('确定要进行操作, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.$axios.post('admin/writer/anime_chapter_review', {
            id: id,
            status: status,
            anid: anid
          }).then((res) => {
            this.$message.success('操作成功!');
            this.getList();
          });
        })
      },
      search() {
        this.params.pagenum = 1;
        this.getList();
      },
    }
  }
</script>

<style scoped>
    .img {
        display: flex;
        align-items: center;
    }

    .img > img {
        margin-right: 10px;
    }
</style>